home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.2 / Bullet / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  10.2 KB  |  369 lines

  1. #include <exec/types.h>
  2. #include <dos/rdargs.h>
  3. #include "libraries/diskfonttag.h"
  4. #include "libraries/glyph.h"
  5.  
  6. #include <clib/exec_protos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/utility_protos.h>
  9. #include "clib/bullet_protos.h"
  10. #include <pragmas/exec_pragmas.h>
  11. #include <pragmas/dos_pragmas.h>
  12. #include <pragmas/utility_pragmas.h>
  13. #include "pragmas/bullet_pragmas.h"
  14.  
  15. #include <math.h>
  16. #include <string.h>
  17. #undef    strchr
  18. #undef    strcmp
  19. #undef    strcpy
  20. #undef    strrchr
  21. #undef    memset
  22.  
  23. extern struct Library *SysBase;
  24. extern struct Library *DOSBase;
  25.  
  26. #define  TEMPLATE1    "NAME,CODE/N,CODE2/N,DPIX/N,DPIY/N,DOTPX/N,DOTPY/N,"
  27. #define  TEMPLATE2    "POINTS/N,SETP/N,SHEAR/N,ROTATE/N,BOLDPX/N,BOLDPY/N,"
  28. #define  TEMPLATE3    "AWIDTHP/N,GLYPH/S,WIDTHS/S,TKERN/S,DKERN/S"
  29. #define  TEMPLATE    TEMPLATE1 TEMPLATE2 TEMPLATE3
  30.  
  31. #define  O_NAME        0
  32. #define  O_CODE        1
  33. #define  O_CODE2    2
  34. #define  O_DPIX        3
  35. #define  O_DPIY        4
  36. #define  O_DOTPX    5
  37. #define  O_DOTPY    6
  38. #define  O_POINTS    7
  39. #define  O_SETP        8
  40. #define  O_SHEAR    9
  41. #define  O_ROTATE    10
  42. #define  O_BOLDPX    11
  43. #define  O_BOLDPY    12
  44. #define  O_AWIDTHP    13
  45. #define  O_GLYPH    14
  46. #define  O_WIDTHS    15
  47. #define  O_TKERN    16
  48. #define  O_DKERN    17
  49. #define  O_COUNT    18
  50.  
  51.  
  52. #define  U_CODE        0
  53. #define  U_CODE2    1
  54. #define  U_DPI        2
  55. #define  U_DOTP        3
  56. #define  U_POINTS    4
  57. #define  U_SETP        5
  58. #define  U_SHEARSIN    6
  59. #define  U_SHEARCOS    7
  60. #define  U_ROTATESIN    8
  61. #define  U_ROTATECOS    9
  62. #define  U_BOLDX    10
  63. #define  U_BOLDY    11
  64. #define  U_AWIDTH    12
  65. #define  U_COUNT    13
  66.  
  67.  
  68. #define  MAXFILESIZE    4000
  69.  
  70. struct Library *UtilityBase = 0;
  71. struct RDArgs *RDArgs = 0;
  72. BPTR OTFile = 0;
  73. struct Library *BulletBase = 0;
  74. struct GlyphEngine *GlyphEngine = 0;
  75. struct TagItem OTags[MAXFILESIZE/sizeof(struct TagItem)];
  76. struct TagItem UTags[U_COUNT+1] = {
  77.     { OT_GlyphCode, 0x0042},
  78.     { OT_GlyphCode2, 0x0000},
  79.     { OT_DeviceDPI, 0x00480048 },
  80.     { OT_DotSize, 0x00640064 },
  81.     { OT_PointHeight, 0x000a0000 },
  82.     { OT_SetFactor, 0x00010000 },
  83.     { OT_ShearSin, 0x00000000 },
  84.     { OT_ShearCos, 0x00010000 },
  85.     { OT_RotateSin, 0x00000000 },
  86.     { OT_RotateCos, 0x00010000 },
  87.     { OT_EmboldenX, 0 },
  88.     { OT_EmboldenY, 0 },
  89.     { OT_GlyphWidth, 0 },
  90.     { TAG_DONE, 0 }
  91. };
  92.  
  93. void
  94. endGame(format, arg1, arg2, arg3, arg4)
  95. char *format, *arg1, *arg2, *arg3, *arg4;
  96. {
  97.     if (format)
  98.     printf(format, arg1, arg2, arg3, arg4);
  99.     if (GlyphEngine)
  100.     CloseEngine(GlyphEngine);
  101.     if (BulletBase)
  102.     CloseLibrary(BulletBase);
  103.     if (OTFile)
  104.     Close(OTFile);
  105.     if (RDArgs)
  106.     FreeArgs(RDArgs);
  107.     if (UtilityBase)
  108.     CloseLibrary(UtilityBase);
  109.     if (format)
  110.     exit(5);
  111.     exit(0);
  112. }
  113.  
  114. ULONG
  115. setInfo(ge, tag)
  116. struct GlyphEngine *ge;
  117. LONG tag;
  118. {
  119.     return(SetInfoA(ge, (struct TagItem *) &tag));
  120. }
  121.  
  122. ULONG
  123. obtainInfo(ge, tag)
  124. struct GlyphEngine *ge;
  125. LONG tag;
  126. {
  127.     return(ObtainInfoA(ge, (struct TagItem *) &tag));
  128. }
  129.  
  130. ULONG
  131. releaseInfo(ge, tag)
  132. struct GlyphEngine *ge;
  133. LONG tag;
  134. {
  135.     return(ReleaseInfoA(ge, (struct TagItem *) &tag));
  136. }
  137.  
  138. void
  139. main()
  140. {
  141.     struct GlyphMap *glyph;
  142.     struct MinList *widthList;
  143.     struct GlyphWidthEntry *widthEntry;
  144.     double angle;
  145.     ULONG error, *options[O_COUNT], result, l;
  146.     short i, x, y;
  147.     char pathStore[256], *filePath, *s;
  148.  
  149.     UtilityBase = OpenLibrary("utility.library", 0);
  150.     if (!UtilityBase)
  151.     endGame("ERROR: cannot open \"utility.library\"\n");
  152.  
  153.     memset(options, 0, sizeof(options));
  154.     RDArgs = ReadArgs(TEMPLATE, (LONG *) options, 0);
  155.     if (!RDArgs)
  156.     endGame("ERROR: invalid arguments\n");
  157.  
  158.     /* generate .otag file path */
  159.     strcpy(pathStore, "FONTS:");
  160.     filePath = pathStore+6;
  161.     if (options[0])
  162.     strcpy(filePath, (char *) options[O_NAME]);
  163.     else
  164.     strcpy(filePath, "CGTimes.font");
  165.     s = strrchr(filePath, '.');
  166.     if ((s == 0) || (strcmp(s, ".font")))
  167.     endGame("ERROR: NAME not .font name\n");
  168.  
  169.     strcpy(s, OTSUFFIX);
  170.  
  171.     /* open .otag file */
  172.     OTFile = Open(filePath, MODE_OLDFILE);
  173.     if (!OTFile) {
  174.     if (!strchr(filePath, ':')) {
  175.         filePath = pathStore;
  176.         OTFile = Open(filePath, MODE_OLDFILE);
  177.     }
  178.     }
  179.  
  180.     if (!OTFile)
  181.     endGame("no font file \"%s\"\n", filePath);
  182.  
  183.     strcpy(s, ".font");
  184.  
  185.     /* read and verify the .otag */
  186.     if (Read(OTFile, OTags, sizeof(struct TagItem)) != sizeof(struct TagItem))
  187.     endGame("OTFile read fail (8 bytes)\n");
  188.  
  189.     if (OTags[0].ti_Tag != OT_FileIdent)
  190.     endGame(".otag first tag $%lx, not $%lx\n", OTags[0].ti_Tag,
  191.         OT_FileIdent);
  192.  
  193.     Seek(OTFile, 0, OFFSET_END);
  194.     if (Seek(OTFile, 0, OFFSET_BEGINNING) != OTags[0].ti_Data)
  195.     endGame(".otag file size wrong\n");
  196.  
  197.     if (OTags[0].ti_Data > MAXFILESIZE)
  198.     endGame(".otag file size %ld larger than program maximum %ld\n",
  199.         OTags[0].ti_Data, MAXFILESIZE);
  200.  
  201.     /* this is a valid .otag file header, read it */
  202.     if (Read(OTFile, OTags, OTags[0].ti_Data) != OTags[0].ti_Data)
  203.     endGame(".otag read failure\n");
  204.  
  205.     /* patch indirect pointers */
  206.     for (i = 0; i < OTags[0].ti_Data/sizeof(struct TagItem); i++) {
  207.     if (OTags[i].ti_Tag == TAG_DONE)
  208.         break;
  209.     if (OTags[i].ti_Tag & OT_Indirect)
  210.         OTags[i].ti_Data += (ULONG) OTags;
  211.     }
  212.  
  213.     /* ensure the associated glyph library is open */
  214.     /* get the library name */
  215.     s = (char *) GetTagData(OT_Engine, 0, OTags);
  216.     if (!s)
  217.     endGame("no OT_Engine tag\n");
  218.  
  219.     if (strcmp(s, "bullet"))
  220.     endGame("OT_Engine not \"bullet\" but \"%s\"\n", s);
  221.  
  222.     BulletBase = OpenLibrary("bullet.library", 0);
  223.     if (!BulletBase)
  224.     endGame("OpenLibrary \"bullet.library\" failed\n");
  225.  
  226.     GlyphEngine = OpenEngine();
  227.  
  228.     if (!GlyphEngine)
  229.     endGame("OpenEngine failed\n");
  230.  
  231.     error = setInfo(GlyphEngine, OT_OTagPath, filePath, TAG_DONE);
  232.     if (error)
  233.     endGame("setInfo(OTagPath) error %ld\n", error);
  234.  
  235.     error = setInfo(GlyphEngine, OT_OTagList, OTags, TAG_DONE);
  236.     if (error)
  237.     endGame("setInfo(OTagList) error %ld\n", error);
  238.  
  239.  
  240.     /* modify environment from .otag */
  241.     if (result = GetTagData(OT_DeviceDPI, 0, OTags))
  242.     UTags[U_DPI].ti_Data = result;
  243.     if (result = GetTagData(OT_DotSize, 0, OTags))
  244.     UTags[U_DOTP].ti_Data = result;
  245.  
  246.     /* modify environment from parameters */
  247.     if (options[O_CODE])
  248.     UTags[U_CODE].ti_Data = *options[O_CODE];
  249.     if (options[O_CODE2])
  250.     UTags[U_CODE2].ti_Data = *options[O_CODE2];
  251.     if (options[O_DPIX] && options[O_DPIY])
  252.     UTags[U_DPI].ti_Data = (*options[O_DPIX]<<16) | *options[O_DPIY];
  253.     if (options[O_DOTPX] && options[O_DOTPY])
  254.     UTags[U_DOTP].ti_Data = (*options[O_DOTPX]<<16) | *options[O_DOTPY];
  255.     if (options[O_POINTS])
  256.     UTags[U_POINTS].ti_Data = *options[O_POINTS]<<16;
  257.     if (options[O_SETP])
  258.     UTags[U_SETP].ti_Data = (*options[O_SETP]<<16)/100;
  259.     if (options[O_SHEAR]) {
  260.     angle = *options[O_SHEAR];
  261.     angle = angle * PI / 180.0;
  262.     if (sin(angle) < 0) {
  263.         UTags[U_SHEARSIN].ti_Data = ((-sin(angle)) * 65536.0);
  264.         UTags[U_SHEARSIN].ti_Data = -UTags[U_SHEARSIN].ti_Data;
  265.     }
  266.     else
  267.         UTags[U_SHEARSIN].ti_Data = (sin(angle) * 65536.0);
  268.     if (cos(angle) < 0) {
  269.         UTags[U_SHEARCOS].ti_Data = ((-cos(angle)) * 65536.0);
  270.         UTags[U_SHEARCOS].ti_Data = -UTags[U_SHEARCOS].ti_Data;
  271.     }
  272.     else
  273.         UTags[U_SHEARCOS].ti_Data = (cos(angle) * 65536.0);
  274.     printf("$%08lx $%08lx\n",
  275.         UTags[U_SHEARSIN].ti_Data, UTags[U_SHEARCOS].ti_Data);
  276.     }
  277.     if (options[O_ROTATE]) {
  278.     angle = *options[O_ROTATE];
  279.     printf("rotate %ld %f degrees, ", angle);
  280.     angle = angle * PI / 180.0;
  281.     printf("%f radians, ", angle);
  282.     if (sin(angle) < 0) {
  283.         UTags[U_ROTATESIN].ti_Data = ((-sin(angle)) * 65536.0);
  284.         UTags[U_ROTATESIN].ti_Data = -UTags[U_ROTATESIN].ti_Data;
  285.     }
  286.     else
  287.         UTags[U_ROTATESIN].ti_Data = (sin(angle) * 65536.0);
  288.     if (cos(angle) < 0) {
  289.         UTags[U_ROTATECOS].ti_Data = ((-cos(angle)) * 65536.0);
  290.         UTags[U_ROTATECOS].ti_Data = -UTags[U_ROTATECOS].ti_Data;
  291.     }
  292.     else
  293.         UTags[U_ROTATECOS].ti_Data = (cos(angle) * 65536.0);
  294.     printf("$%08lx $%08lx\n",
  295.         UTags[U_ROTATESIN].ti_Data, UTags[U_ROTATECOS].ti_Data);
  296.     }
  297.     if (options[O_BOLDPX])
  298.     UTags[U_BOLDX].ti_Data = (*options[O_BOLDPX]<<16)/100;
  299.     if (options[O_BOLDPY])
  300.     UTags[U_BOLDY].ti_Data = (*options[O_BOLDPY]<<16)/100;
  301.     if (options[O_AWIDTHP])
  302.     UTags[U_AWIDTH].ti_Data = (*options[O_AWIDTHP]<<16)/100;
  303.  
  304.     SetInfoA(GlyphEngine, UTags);
  305.  
  306.     if (options[O_GLYPH]) {
  307.     error = obtainInfo(GlyphEngine, OT_GlyphMap, &glyph, TAG_DONE);
  308.     if (error)
  309.         endGame("obtainInfo(Glyph) error %ld\n", error);
  310.     printf("glyph $%lx, width %ld, height %ld, bitmap $%lx\n",
  311.         glyph, glyph->glm_BMModulo, glyph->glm_BMRows,
  312.         glyph->glm_BitMap);
  313.     printf("    Black- Left %ld, Top %ld, Width %ld, Height %ld\n",
  314.         glyph->glm_BlackLeft, glyph->glm_BlackTop,
  315.         glyph->glm_BlackWidth, glyph->glm_BlackHeight);
  316.     printf("    xOrigin $%08lx, yOrigin $%08lx\n",
  317.         glyph->glm_XOrigin, glyph->glm_YOrigin);
  318.     printf("    x0 y0 %ld %ld,    x1 y1 %ld %ld\n",
  319.         glyph->glm_X0, glyph->glm_Y0, glyph->glm_X1, glyph->glm_Y1);
  320.     printf("    width %ld.%04ld\n", glyph->glm_Width>>16,
  321.         ((glyph->glm_Width&0xffff)*10000)>>16);
  322.     for (y = 0; y < glyph->glm_BMRows; y++) {
  323.         for (x = 0; x < glyph->glm_BMModulo; x++) {
  324.         for (i = 0x80; i; i>>=1) {
  325.             if (((char *)(glyph->glm_BitMap))[(y*glyph->glm_BMModulo)+x]
  326.                 & i)
  327.             printf("*");
  328.             else
  329.             printf("-");
  330.         }
  331.         }
  332.         printf("\n");
  333.     }
  334.     releaseInfo(GlyphEngine, OT_GlyphMap, glyph, TAG_DONE);
  335.     }
  336.     if (options[O_WIDTHS]) {
  337.     error = obtainInfo(GlyphEngine, OT_WidthList, &widthList, TAG_DONE);
  338.     if (error)
  339.         endGame("obtainInfo(WidthList) error %ld\n", error);
  340.     printf("widthList $%lx...\n", widthList);
  341.     for (widthEntry = (struct GlyphWidthEntry *) widthList->mlh_Head;
  342.         widthEntry->gwe_Node.mln_Succ;
  343.         widthEntry = (struct GlyphWidthEntry *)
  344.         widthEntry->gwe_Node.mln_Succ) {
  345.         printf("$%04lx: %ld.%04ld\n",
  346.             widthEntry->gwe_Code,
  347.             widthEntry->gwe_Width>>16,
  348.             ((widthEntry->gwe_Width&0xffff)*10000)>>16);
  349.     }
  350.     releaseInfo(GlyphEngine, OT_WidthList, widthList, TAG_DONE);
  351.     }
  352.     if (options[O_TKERN]) {
  353.     error = obtainInfo(GlyphEngine, OT_TextKernPair, &l, TAG_DONE);
  354.     if (error)
  355.         endGame("obtainInfo(TextKernPair) error %ld\n", error);
  356.     printf("Text Kern $%08lx:$%08lx %ld.%04ld\n", UTags[U_CODE].ti_Data,
  357.         UTags[U_CODE2].ti_Data, l>>16, ((l&0xffff)*10000)>>16);
  358.     }
  359.     if (options[O_DKERN]) {
  360.     error = obtainInfo(GlyphEngine, OT_DesignKernPair, &l, TAG_DONE);
  361.     if (error)
  362.         endGame("obtainInfo(DesignKernPair) error %ld\n", error);
  363.     printf("Design Kern $%08lx:$%08lx %ld.%04ld\n", UTags[U_CODE].ti_Data,
  364.         UTags[U_CODE2].ti_Data, l>>16, ((l&0xffff)*10000)>>16);
  365.     }
  366.  
  367.     endGame(0);
  368. }
  369.